﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using StockStar.GatherData;
using System.Data;
using System.Data.SqlClient;
using System.Xml;

namespace Stockstar.Stock.Gather
{
    public class GatherData
    {
        public void DoWork()
        {  
            //sos();

            //IrtZfListUrl(1);
            //UpZfListByUrl();

            //IrtKzzListUrl(1);
            //UpKzzListByUrl();

            //IrtShListUrl(1);
            //UpShListByUrl();

            //抓取交易提示
            UpJyts();
            UpShJygkxx();

            UpXgReportByUrl();
            upFuture();

            //新股
            IrtXgListUrl(1);
            UpXgListByUrl();
            UpAllXgListByUrl();

            //新股公告
            UpAllXgGG();
            UpAllXgGGContent();

            Console.WriteLine("done");
            //Console.Read();
        }

        #region 新股部分
        /// <summary>
        /// 采集新投http://data.eastmoney.com/xg/xg/default.html UrlList
        /// </summary>
        /// <param name="page">传入采集第几页,page=0采集所有页</param>
        private static void IrtXgListUrl(int page)
        {
            StringBuilder sql = new StringBuilder();
            List<XgDetailEntity> ListAll = (List<XgDetailEntity>)NewsList.XgListAll("");

            string _url = "", _Content = "";
            int _page = 1;
            if (page == 0)
            {
                _url = "http://data.eastmoney.com/xg/xg/default.html";
                _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                Match mc = Regex.Match(_Content, "(?<=<tr class=\"list_pager\">)[\\s\\S]*?(?=</tr>)");
                if (mc.Length > 0)
                {
                    Match mc2 = Regex.Match(mc.Value, "(?<=共)[\\s\\S]*?(?=页)", RegexOptions.IgnoreCase);
                    if (mc2.Length > 0)
                        _page = OperMethod.ToInt(OperMethod.StrReplaceHtml(mc2.Value));
                }
            }

            for (int i = 1; i <= _page; i++)
            {
                try
                {
                    _url = "http://data.eastmoney.com/xg/xg/sgrq/" + i.ToString() + ".html";
                    _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    MatchCollection mc = Regex.Matches(_Content, "(?<=title=\"按股票代码排序\")[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                    if (mc.Count > 0)
                    {
                        #region
                        MatchCollection mc2 = Regex.Matches(mc[0].Value, "<a[^>]+>[\\S\\s]*?</a>",RegexOptions.IgnoreCase);
                        if (mc2.Count > 0)
                        {
                            for (int j = 0; j < mc2.Count; j++)
                            {
                                try
                                {
                                    if (mc2[j].Value.Contains("详细"))
                                    {
                                        Match mc3 = Regex.Match(mc2[j].Value, "(?<=<a href=\")[\\s\\S]*?(?=\")");
                                        if (mc3.Length > 0)
                                        {
                                            XgDetailEntity et = new XgDetailEntity();
                                            et.Url = "http://data.eastmoney.com" + OperMethod.StrReplaceHtml(mc3.Value);
                                            List<XgDetailEntity> MidList = (List<XgDetailEntity>)ListAll.Where(o => o.Url.Equals(et.Url)).ToList();
                                            if (MidList == null || MidList.Count < 1)
                                            {
                                                sql.Append("insert XG_Detail (url,flag,createtime) values ('" + et.Url + "',-1,'" + DateTime.Now + "')      ;\n");
                                            }
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("取列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                                    LogFile.WriteLog("取列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                                }
                            }
                        }
                        #endregion
                    }

                    if (!string.IsNullOrEmpty(sql.ToString()))
                    {
                        SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        sql = new StringBuilder();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("取新股第" + i + "页信息时出错");
                    LogFile.WriteLog("取新股第" + i + "页信息时出错");
                }
            }
        }

        /// <summary>
        /// 更新新股UrlList信息
        /// </summary>
        private static void UpXgListByUrl()
        {
            StringBuilder sql = new StringBuilder();
            Regex regex = new Regex("<td[^>][\\S\\s]*?>|</td>|<div[^>][\\S\\s]*?>|</div>");
            List<XgDetailEntity> ListAll = (List<XgDetailEntity>)NewsList.XgListAll("and flag=-1");
            List<XgDetailEntity> MidList = (List<XgDetailEntity>)ListAll.Where(o => o.Flag.Equals(-1)).ToList();
            for (int i = 0; i < MidList.Count; i++)
            {
                try
                {
                    Console.WriteLine("采集第i=" + i.ToString() + "条信息");
                    string _url = MidList[i].Url;
                    int _ID = MidList[i].ID;
                    //_url = "http://data.eastmoney.com/xg/xg/detail/300054.html";
                    string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mcSubCon = Regex.Match(_Content, "(?<=id=\"content\" class=\"mainbox\">)[\\s\\S]*?(?=id=\"footer\">)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mcSubCon.Value))
                    {
                        //XG_Detail新股详细资料
                        #region
                        StringBuilder sbDetail = new StringBuilder();
                        Match mcDetail = Regex.Match(mcSubCon.Value, "(?<=class=\"detail\">)[\\s\\S]*?(?=<div class=\"s8\"></div>)", RegexOptions.IgnoreCase);
                        if (string.IsNullOrEmpty(mcDetail.Value))
                            mcDetail = Regex.Match(mcSubCon.Value, "(?<=class=\"detail\">)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);

                        if (!string.IsNullOrEmpty(mcDetail.Value))
                        {
                            XgDetailEntity et = new XgDetailEntity();
                            MatchCollection mcTd = Regex.Matches(mcDetail.Value, "<td[\\S\\s]*?>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                            DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
                            for (int j = 0; j < mcTd.Count; j++)
                            {
                                #region
                                try
                                {
                                    if (mcTd[j].Value.Contains("股票代码"))
                                    {
                                        j++;
                                        et.Gpdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("股票简称"))
                                    {
                                        j++;
                                        et.Gpjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("申购代码"))
                                    {
                                        j++;
                                        et.Sgdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("上市地点"))
                                    {
                                        j++;
                                        et.Ssdd = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行价格"))
                                    {
                                        j++;
                                        et.Fxjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行市盈率"))
                                    {
                                        j++;
                                        et.Fxsyl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行面值"))
                                    {
                                        j++;
                                        et.Fxmz = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("实际募集资金总额"))
                                    {
                                        j++;
                                        et.Mjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网上发行日期"))
                                    {
                                        j++;
                                        et.Fxrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网上发行股数"))
                                    {
                                        j++;
                                        et.Fxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网下配售日期"))
                                    {
                                        j++;
                                        et.Psrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网下配售股数"))
                                    {
                                        j++;
                                        et.Psgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("申购数量上限"))
                                    {
                                        j++;
                                        et.Sgsl = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("总发行股数"))
                                    {
                                        j++;
                                        et.Zfxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("中签号公告日"))
                                    {
                                        j++;
                                        et.Zqhggr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("上市日期"))
                                    {
                                        j++;
                                        et.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网下配售比例"))
                                    {
                                        j++;
                                        et.Psbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网下配售冻结资金"))
                                    {
                                        j++;
                                        et.Psdjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网上发行中签率"))
                                    {
                                        j++;
                                        et.Fxzql = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网上申购冻结资金"))
                                    {
                                        j++;
                                        et.Sgdjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网上发行每中一签约"))
                                    {
                                        j++;
                                        et.Fxqy = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("冻结资金总计"))
                                    {
                                        j++;
                                        et.Djzjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("中签号"))
                                    {
                                        j++;
                                        et.Zqh = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Zqh = regex.Replace(et.Zqh, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("公司简介"))
                                    {
                                        j++;
                                        et.Gsjj = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Gsjj = regex.Replace(et.Gsjj, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("主营业务"))
                                    {
                                        j++;
                                        et.Zyyw = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Zyyw = regex.Replace(et.Zyyw, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行前每股净资产"))
                                    {
                                        j++;
                                        et.Fxq = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行后每股净资产"))
                                    {
                                        j++;
                                        et.Fxh = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("上市推荐人"))
                                    {
                                        j++;
                                        et.Tjr = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("承销方式"))
                                    {
                                        j++;
                                        et.Cxfs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("副主承销商"))
                                    {
                                        j++;
                                        et.Fzcxs = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Fzcxs = regex.Replace(et.Fzcxs, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("主承销商"))
                                    {
                                        j++;
                                        et.Zcxs = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Zcxs = regex.Replace(et.Zcxs, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("股利分配政策"))
                                    {
                                        j++;
                                        et.Glfpzc = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Glfpzc = regex.Replace(et.Glfpzc, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("首日开盘价"))
                                    {
                                        j++;
                                        et.Kpj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("首日收盘价"))
                                    {
                                        j++;
                                        et.Spj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("首日涨幅"))
                                    {
                                        j++;
                                        et.Zf = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("首日换手率"))
                                    {
                                        j++;
                                        et.Hsl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Detail取字段" + mcTd[j].Value + "附近异常:" + ex.Message);
                                    LogFile.WriteLog("Detail取字段" + mcTd[j].Value + "附近异常:" + ex.Message);
                                }
                                #endregion
                            }

                            //拼sbDetail Sql
                            #region
                            sbDetail.Append("UPDATE [XG_Detail]");
                            sbDetail.Append(" SET [flag] = 1");
                            sbDetail.Append(" ,[gpdm] = '" + et.Gpdm + "'");
                            sbDetail.Append(" ,[gpjc] = '" + et.Gpjc + "'");
                            sbDetail.Append(" ,[sgdm] = '" + et.Sgdm + "'");
                            sbDetail.Append(" ,[ssdd] = '" + et.Ssdd + "'");
                            sbDetail.Append(" ,[fxjg] = " + et.Fxjg + "");
                            sbDetail.Append(" ,[fxsyl] = " + et.Fxsyl + "");
                            sbDetail.Append(" ,[fxmz] = " + et.Fxmz + "");
                            sbDetail.Append(" ,[mjzj] = " + et.Mjzj + "");
                            sbDetail.Append(" ,[fxrq] = '" + et.Fxrq + "'");
                            sbDetail.Append(" ,[fxgs] = " + et.Fxgs + "");
                            sbDetail.Append(" ,[psrq] = '" + et.Psrq + "'");
                            sbDetail.Append(" ,[psgs] = " + et.Psgs + "");
                            sbDetail.Append(" ,[sgsl] = " + et.Sgsl + "");
                            sbDetail.Append(" ,[zfxgs] = " + et.Zfxgs + "");
                            sbDetail.Append(" ,[zqhggr] = '" + et.Zqhggr + "'");
                            sbDetail.Append(" ,[ssrq] = '" + et.Ssrq + "'");
                            sbDetail.Append(" ,[psbl] = " + et.Psbl + "");
                            sbDetail.Append(" ,[psdjzj] = " + et.Psdjzj + "");
                            sbDetail.Append(" ,[fxzql] = " + et.Fxzql + "");
                            sbDetail.Append(" ,[sgdjzj] = " + et.Sgdjzj + "");
                            sbDetail.Append(" ,[fxqy] = " + et.Fxqy + "");
                            sbDetail.Append(" ,[Djzjzj] = " + et.Djzjzj + "");
                            sbDetail.Append(" ,[zqh] = '" + et.Zqh + "'");
                            sbDetail.Append(" ,[gsjj] = '" + et.Gsjj + "'");
                            sbDetail.Append(" ,[zyyw] = '" + et.Zyyw + "'");
                            sbDetail.Append(" ,[fxq] = " + et.Fxq + "");
                            sbDetail.Append(" ,[fxh] = " + et.Fxh + "");
                            sbDetail.Append(" ,[tjr] = '" + et.Tjr + "'");
                            sbDetail.Append(" ,[cxfs] = '" + et.Cxfs + "'");
                            sbDetail.Append(" ,[zcxs] = '" + et.Zcxs + "'");
                            sbDetail.Append(" ,[fzcxs] = '" + et.Fzcxs + "'");
                            sbDetail.Append(" ,[glfpzc] = '" + et.Glfpzc + "'");
                            sbDetail.Append(" ,[kpj] = " + et.Kpj + "");
                            sbDetail.Append(" ,[spj] = " + et.Spj + "");
                            sbDetail.Append(" ,[zf] = " + et.Zf + "");
                            sbDetail.Append(" ,[hsl] = " + et.Hsl + "");
                            sbDetail.Append(" ,[createtime] = '" + DateTime.Now + "'");
                            sbDetail.Append(" WHERE ID=" + _ID);
                            Console.WriteLine("Detail拼Sql完成");
                            #endregion
                        }
                        #endregion

                        //XG_Invset投资项目
                        #region
                        StringBuilder sbInvset = new StringBuilder();
                        Match mcInvset = Regex.Match(mcSubCon.Value, "(?<=募集资金用途将用于的项目</div>)[\\s\\S]*?(?=<div class=\"s8\"></div>)", RegexOptions.IgnoreCase);
                        if (!string.IsNullOrEmpty(mcInvset.Value))
                        {
                            MatchCollection mcTr = Regex.Matches(mcInvset.Value, "(?<=class=\"list_eve\">)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                            for (int k = 0; k < mcTr.Count; k++)
                            {
                                try
                                {
                                    MatchCollection mcTd = Regex.Matches(mcTr[k].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                                    if (mcTd.Count == 3)
                                    {
                                        XgInvsetEntity et = new XgInvsetEntity();
                                        et.Xmmc = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                        et.Tzje = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[2].Value));
                                        sbInvset.Append("Insert into XG_Invset (id,xmmc,tzje) values (" + _ID + ",'" + et.Xmmc + "'," + et.Tzje + ")    ;\n");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("募集资金用途将用于的项目异常:" + ex.Message);
                                    LogFile.WriteLog("募集资金用途将用于的项目异常:" + ex.Message);
                                }
                            }
                        }
                        Console.WriteLine("取XG_Invset投资项目信息完成");
                        #endregion

                        //XG_Indicators财务指标
                        #region
                        StringBuilder sbIndicator = new StringBuilder();
                        Match mcIndicator = Regex.Match(mcSubCon.Value, "(?<=最近三年财务指标</div>)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                        if (!string.IsNullOrEmpty(mcIndicator.Value))
                        {
                            List<EntityIndicatorCol> CList = new List<EntityIndicatorCol>();
                            MatchCollection mcTr = Regex.Matches(mcIndicator.Value, "(?<=<tr)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                            for (int m = 0; m < mcTr.Count; m++)
                            {
                                try
                                {
                                    EntityIndicatorCol cet = new EntityIndicatorCol();
                                    if (mcTr[m].Value.Contains("class=\"subhead\">"))
                                    {
                                        MatchCollection mcTd = Regex.Matches(mcTr[m].Value, "<th[\\S\\s]*?>[\\S\\s]*?</th>", RegexOptions.IgnoreCase);
                                        if (mcTd.Count > 0)
                                        {
                                            cet.zd = OperMethod.StrReplaceHtml(mcTd[0].Value);
                                            cet.c1 = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                            cet.c2 = OperMethod.StrReplaceHtml(mcTd[2].Value);
                                            cet.c3 = OperMethod.StrReplaceHtml(mcTd[3].Value);
                                            CList.Add(cet);
                                        }
                                        continue;
                                    }
                                    if (mcTr[m].Value.Contains("class=\"list_eve\">"))
                                    {
                                        MatchCollection mcTd = Regex.Matches(mcTr[m].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                                        if (mcTd.Count > 0)
                                        {
                                            cet.zd = OperMethod.StrReplaceHtml(mcTd[0].Value);
                                            cet.c1 = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                            cet.c2 = OperMethod.StrReplaceHtml(mcTd[2].Value);
                                            cet.c3 = OperMethod.StrReplaceHtml(mcTd[3].Value);
                                            CList.Add(cet);
                                        }
                                        continue;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("解析装载到List出错:" + ex.Message);
                                    LogFile.WriteLog("解析装载到List出错:" + ex.Message);
                                }
                            }

                            if (CList.Count == 11)
                            {
                                sbIndicator.Append(" INSERT INTO [XG_Indicators] ");
                                sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                                sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c1 + "'," + OperMethod.ToDeceimal(CList[1].c1) + "," + OperMethod.ToDeceimal(CList[2].c1) + "," + OperMethod.ToDeceimal(CList[3].c1) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c1) + "," + OperMethod.ToDeceimal(CList[5].c1) + "," + OperMethod.ToDeceimal(CList[6].c1) + "," + OperMethod.ToDeceimal(CList[7].c1) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c1) + "," + OperMethod.ToDeceimal(CList[9].c1) + "," + OperMethod.ToDeceimal(CList[10].c1) + ")    ;\n");

                                sbIndicator.Append(" INSERT INTO [XG_Indicators] ");
                                sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                                sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c2 + "'," + OperMethod.ToDeceimal(CList[1].c2) + "," + OperMethod.ToDeceimal(CList[2].c2) + "," + OperMethod.ToDeceimal(CList[3].c2) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c2) + "," + OperMethod.ToDeceimal(CList[5].c2) + "," + OperMethod.ToDeceimal(CList[6].c2) + "," + OperMethod.ToDeceimal(CList[7].c2) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c2) + "," + OperMethod.ToDeceimal(CList[9].c2) + "," + OperMethod.ToDeceimal(CList[10].c2) + ")    ;\n");

                                sbIndicator.Append(" INSERT INTO [XG_Indicators] ");
                                sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                                sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c3 + "'," + OperMethod.ToDeceimal(CList[1].c3) + "," + OperMethod.ToDeceimal(CList[2].c3) + "," + OperMethod.ToDeceimal(CList[3].c3) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c3) + "," + OperMethod.ToDeceimal(CList[5].c3) + "," + OperMethod.ToDeceimal(CList[6].c3) + "," + OperMethod.ToDeceimal(CList[7].c3) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c3) + "," + OperMethod.ToDeceimal(CList[9].c3) + "," + OperMethod.ToDeceimal(CList[10].c3) + ")    ;\n");
                            }
                        }
                        Console.WriteLine("取XG_Indicators最近三年财务指标完成");
                        #endregion

                        //XG_Partner主要股东
                        #region
                        StringBuilder sbPartner = new StringBuilder();
                        Match mcPartner = Regex.Match(mcSubCon.Value, "(?<=主要股东</div>)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                        if (!string.IsNullOrEmpty(mcPartner.Value))
                        {
                            MatchCollection mcTr = Regex.Matches(mcPartner.Value, "(?<=class=\"list_eve\">)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                            for (int x = 0; x < mcTr.Count; x++)
                            {
                                try
                                {
                                    MatchCollection mcTd = Regex.Matches(mcTr[x].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                                    if (mcTd.Count == 4)
                                    {
                                        XgPaterEntity et = new XgPaterEntity();
                                        et.Gdmc = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                        et.Cgsl = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[2].Value));
                                        et.Gbbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[3].Value));
                                        sbPartner.Append("INSERT INTO [XG_Partner] ([id],[gdmc],[cgsl],[gbbl]) VALUES (" + _ID + ",'" + et.Gdmc + "'," + et.Cgsl + "," + et.Gbbl + ")    ;\n");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("主要股东异常:" + ex.Message);
                                    LogFile.WriteLog("主要股东异常:" + ex.Message);
                                }
                            }
                        }
                        Console.WriteLine("取XG_Partner主要股东完成");
                        #endregion

                        //执行Sql
                        #region
                        using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                        {
                            conn.Open();
                            using (SqlTransaction trans = conn.BeginTransaction())
                            {
                                try
                                {
                                    if (!string.IsNullOrEmpty(sbDetail.ToString()))
                                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbDetail.ToString(), null);
                                    if (!string.IsNullOrEmpty(sbInvset.ToString()))
                                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbInvset.ToString(), null);
                                    if (!string.IsNullOrEmpty(sbIndicator.ToString()))
                                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbIndicator.ToString(), null);
                                    if (!string.IsNullOrEmpty(sbPartner.ToString()))
                                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbPartner.ToString(), null);
                                    trans.Commit();
                                    Console.WriteLine("ID=" + _ID + ",Url=" + _url + "信息更新成功!");
                                }
                                catch (Exception ex)
                                {
                                    trans.Rollback();
                                    Console.WriteLine("执行Sql异常,ID:" + _ID + ":" + ex.Message);
                                    LogFile.WriteLog("执行Sql异常,ID:" + _ID + ":" + ex.Message);
                                }
                                finally
                                {
                                    sbDetail = new StringBuilder();
                                    sbInvset = new StringBuilder();
                                    sbIndicator = new StringBuilder();
                                    sbPartner = new StringBuilder();
                                }
                            }
                        }
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集第i=" + i.ToString() + "条信息异常" + ex.Message);
                    LogFile.WriteLog("采集第i=" + i.ToString() + "条信息异常" + ex.Message);
                }
            }
            Console.WriteLine("新股信息更新成功");
        }

        /// <summary>
        /// 更新所有新股UrlList信息
        /// </summary>
        private static void UpAllXgListByUrl()
        {
            StringBuilder sql = new StringBuilder();
            Regex regex = new Regex("<td[^>][\\S\\s]*?>|</td>|<div[^>][\\S\\s]*?>|</div>");
            List<XgDetailEntity> ListAll = (List<XgDetailEntity>)NewsList.XgListAll("and flag=0");
            List<XgDetailEntity> MidList = (List<XgDetailEntity>)ListAll.ToList();
            for (int i = 0; i < MidList.Count; i++)
            {
                try
                {
                    Console.WriteLine("采集第i=" + i.ToString() + "条信息");
                    string _url = MidList[i].Url;
                    int _ID = MidList[i].ID;
                    //_url = "http://data.eastmoney.com/xg/xg/detail/300054.html";
                    string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mcSubCon = Regex.Match(_Content, "(?<=id=\"content\" class=\"mainbox\">)[\\s\\S]*?(?=id=\"footer\">)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mcSubCon.Value))
                    {
                        //XG_Detail新股详细资料
                        #region
                        StringBuilder sbDetail = new StringBuilder();
                        Match mcDetail = Regex.Match(mcSubCon.Value, "(?<=class=\"detail\">)[\\s\\S]*?(?=<div class=\"s8\"></div>)", RegexOptions.IgnoreCase);
                        if (string.IsNullOrEmpty(mcDetail.Value))
                            mcDetail = Regex.Match(mcSubCon.Value, "(?<=class=\"detail\">)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);

                        if (!string.IsNullOrEmpty(mcDetail.Value))
                        {
                            XgDetailEntity et = new XgDetailEntity();
                            MatchCollection mcTd = Regex.Matches(mcDetail.Value, "<td[\\S\\s]*?>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                            DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
                            for (int j = 0; j < mcTd.Count; j++)
                            {
                                #region
                                try
                                {
                                    if (mcTd[j].Value.Contains("股票代码"))
                                    {
                                        j++;
                                        et.Gpdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("股票简称"))
                                    {
                                        j++;
                                        et.Gpjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("申购代码"))
                                    {
                                        j++;
                                        et.Sgdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("上市地点"))
                                    {
                                        j++;
                                        et.Ssdd = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行价格"))
                                    {
                                        j++;
                                        et.Fxjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行市盈率"))
                                    {
                                        j++;
                                        et.Fxsyl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行面值"))
                                    {
                                        j++;
                                        et.Fxmz = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("实际募集资金总额"))
                                    {
                                        j++;
                                        et.Mjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网上发行日期"))
                                    {
                                        j++;
                                        et.Fxrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网上发行股数"))
                                    {
                                        j++;
                                        et.Fxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网下配售日期"))
                                    {
                                        j++;
                                        et.Psrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网下配售股数"))
                                    {
                                        j++;
                                        et.Psgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("申购数量上限"))
                                    {
                                        j++;
                                        et.Sgsl = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("总发行股数"))
                                    {
                                        j++;
                                        et.Zfxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("中签号公告日"))
                                    {
                                        j++;
                                        et.Zqhggr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("上市日期"))
                                    {
                                        j++;
                                        et.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网下配售比例"))
                                    {
                                        j++;
                                        et.Psbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网下配售冻结资金"))
                                    {
                                        j++;
                                        et.Psdjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网上发行中签率"))
                                    {
                                        j++;
                                        et.Fxzql = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网上申购冻结资金"))
                                    {
                                        j++;
                                        et.Sgdjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("网上发行每中一签约"))
                                    {
                                        j++;
                                        et.Fxqy = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("冻结资金总计"))
                                    {
                                        j++;
                                        et.Djzjzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("中签号"))
                                    {
                                        j++;
                                        et.Zqh = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Zqh = regex.Replace(et.Zqh, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("公司简介"))
                                    {
                                        j++;
                                        et.Gsjj = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Gsjj = regex.Replace(et.Gsjj, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("主营业务"))
                                    {
                                        j++;
                                        et.Zyyw = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Zyyw = regex.Replace(et.Zyyw, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行前每股净资产"))
                                    {
                                        j++;
                                        et.Fxq = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行后每股净资产"))
                                    {
                                        j++;
                                        et.Fxh = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("上市推荐人"))
                                    {
                                        j++;
                                        et.Tjr = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("承销方式"))
                                    {
                                        j++;
                                        et.Cxfs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("副主承销商"))
                                    {
                                        j++;
                                        et.Fzcxs = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Fzcxs = regex.Replace(et.Fzcxs, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("主承销商"))
                                    {
                                        j++;
                                        et.Zcxs = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Zcxs = regex.Replace(et.Zcxs, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("股利分配政策"))
                                    {
                                        j++;
                                        et.Glfpzc = OperMethod.FormatHtml(mcTd[j].Value);
                                        et.Glfpzc = regex.Replace(et.Glfpzc, "");
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("首日开盘价"))
                                    {
                                        j++;
                                        et.Kpj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("首日收盘价"))
                                    {
                                        j++;
                                        et.Spj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("首日涨幅"))
                                    {
                                        j++;
                                        et.Zf = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("首日换手率"))
                                    {
                                        j++;
                                        et.Hsl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Detail取字段" + mcTd[j].Value + "附近异常:" + ex.Message);
                                    LogFile.WriteLog("Detail取字段" + mcTd[j].Value + "附近异常:" + ex.Message);
                                }
                                #endregion
                            }

                            //拼sbDetail Sql
                            #region
                            sbDetail.Append("UPDATE [XG_Detail]");
                            sbDetail.Append(" SET [flag] = 0");
                            sbDetail.Append(" ,[gpdm] = '" + et.Gpdm + "'");
                            sbDetail.Append(" ,[gpjc] = '" + et.Gpjc + "'");
                            sbDetail.Append(" ,[sgdm] = '" + et.Sgdm + "'");
                            sbDetail.Append(" ,[ssdd] = '" + et.Ssdd + "'");
                            sbDetail.Append(" ,[fxjg] = " + et.Fxjg + "");
                            sbDetail.Append(" ,[fxsyl] = " + et.Fxsyl + "");
                            sbDetail.Append(" ,[fxmz] = " + et.Fxmz + "");
                            sbDetail.Append(" ,[mjzj] = " + et.Mjzj + "");
                            sbDetail.Append(" ,[fxrq] = '" + et.Fxrq + "'");
                            sbDetail.Append(" ,[fxgs] = " + et.Fxgs + "");
                            sbDetail.Append(" ,[psrq] = '" + et.Psrq + "'");
                            sbDetail.Append(" ,[psgs] = " + et.Psgs + "");
                            sbDetail.Append(" ,[sgsl] = " + et.Sgsl + "");
                            sbDetail.Append(" ,[zfxgs] = " + et.Zfxgs + "");
                            sbDetail.Append(" ,[zqhggr] = '" + et.Zqhggr + "'");
                            sbDetail.Append(" ,[ssrq] = '" + et.Ssrq + "'");
                            sbDetail.Append(" ,[psbl] = " + et.Psbl + "");
                            sbDetail.Append(" ,[psdjzj] = " + et.Psdjzj + "");
                            sbDetail.Append(" ,[fxzql] = " + et.Fxzql + "");
                            sbDetail.Append(" ,[sgdjzj] = " + et.Sgdjzj + "");
                            sbDetail.Append(" ,[fxqy] = " + et.Fxqy + "");
                            sbDetail.Append(" ,[Djzjzj] = " + et.Djzjzj + "");
                            sbDetail.Append(" ,[zqh] = '" + et.Zqh + "'");
                            sbDetail.Append(" ,[gsjj] = '" + et.Gsjj + "'");
                            sbDetail.Append(" ,[zyyw] = '" + et.Zyyw + "'");
                            sbDetail.Append(" ,[fxq] = " + et.Fxq + "");
                            sbDetail.Append(" ,[fxh] = " + et.Fxh + "");
                            sbDetail.Append(" ,[tjr] = '" + et.Tjr + "'");
                            sbDetail.Append(" ,[cxfs] = '" + et.Cxfs + "'");
                            sbDetail.Append(" ,[zcxs] = '" + et.Zcxs + "'");
                            sbDetail.Append(" ,[fzcxs] = '" + et.Fzcxs + "'");
                            sbDetail.Append(" ,[glfpzc] = '" + et.Glfpzc + "'");
                            sbDetail.Append(" ,[kpj] = " + et.Kpj + "");
                            sbDetail.Append(" ,[spj] = " + et.Spj + "");
                            sbDetail.Append(" ,[zf] = " + et.Zf + "");
                            sbDetail.Append(" ,[hsl] = " + et.Hsl + "");
                            sbDetail.Append(" ,[createtime] = '" + DateTime.Now + "'");
                            sbDetail.Append(" WHERE ID=" + _ID);
                            Console.WriteLine("Detail拼Sql完成");
                            #endregion
                        }

                        sbDetail.Append("update [XG_Detail] set flag=0 where flag=1");
                        #endregion                     
                        //执行Sql
                        #region
                        using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                        {
                            conn.Open();
                            using (SqlTransaction trans = conn.BeginTransaction())
                            {
                                try
                                {
                                    if (!string.IsNullOrEmpty(sbDetail.ToString()))
                                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbDetail.ToString(), null);
                                    //if (!string.IsNullOrEmpty(sbInvset.ToString()))
                                    //    SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbInvset.ToString(), null);
                                    //if (!string.IsNullOrEmpty(sbIndicator.ToString()))
                                    //    SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbIndicator.ToString(), null);
                                    //if (!string.IsNullOrEmpty(sbPartner.ToString()))
                                    //    SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbPartner.ToString(), null);
                                    trans.Commit();
                                    Console.WriteLine("ID=" + _ID + ",Url=" + _url + "信息更新成功!");
                                }
                                catch (Exception ex)
                                {
                                    trans.Rollback();
                                    Console.WriteLine("执行Sql异常,ID:" + _ID + ":" + ex.Message);
                                    LogFile.WriteLog("执行Sql异常,ID:" + _ID + ":" + ex.Message);
                                }
                                finally
                                {
                                    sbDetail = new StringBuilder();
                                    //sbInvset = new StringBuilder();
                                    //sbIndicator = new StringBuilder();
                                    //sbPartner = new StringBuilder();
                                }
                            }
                        }
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集第i=" + i.ToString() + "条信息异常" + ex.Message);
                    LogFile.WriteLog("采集第i=" + i.ToString() + "条信息异常" + ex.Message);
                }
            }
            Console.WriteLine("新股信息更新成功");
        }
        
        /// <summary>
        /// 更新所有新股公告
        /// </summary>
        private static void UpAllXgGG() 
        {
            //Match mcSubCon = Regex.Match(content, "<li><span class=\"text\"><a [^>]+>[\w\W]+", RegexOptions.IgnoreCase);
            List<string> stocks = NewsList.GetXgCode();
            foreach (string code in stocks)
            {
                UpXgGG(code);         
            }            

            Console.WriteLine("新股公告信息更新完成!");

        }

        /// <summary>
        /// 采集所有新股公告的内容
        /// </summary>
        private static void UpAllXgGGContent() 
        {
            List<XgGgEntity> list = NewsList.XgGgListQuery(" and flag=-1");           
            foreach (XgGgEntity gg in list) 
            {
                StringBuilder sqlsb = new StringBuilder();
                string _url = string.Format("http://data.eastmoney.com/Notice/{0}", gg.Url);
                Console.WriteLine("开始采集" + _url + "公告信息");
                string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                Match mc = Regex.Match(_Content, "<pre>[\\S\\s]+</pre>", RegexOptions.IgnoreCase);
                _Content = Regex.Replace(mc.Value, "<?pre>", "", RegexOptions.IgnoreCase);
                _Content = _Content.Replace("'", "''");
                sqlsb.AppendFormat("Update xg_gg set content='{0}',flag=0 where id={1}\r\n", _Content, gg.ID);
                //break;

                using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sqlsb.ToString(), null);
                            trans.Commit();
                            Console.WriteLine("新股公告内容更新成功!");
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            Console.WriteLine("新股公告内容" + _url + "更新异常:" + ex.Message);
                            LogFile.WriteLog("新股公告内容" + _url + "更新异常:" + ex.Message);
                        }
                    }
                }
            }

            Console.WriteLine("新股公告内容更新完成!");
        }

        private static void sos() 
        {
            List<XgGgEntity> ListAll = (List<XgGgEntity>)NewsList.XgGgListQuery("");
            foreach (XgGgEntity xg in ListAll)
            {
                string sql = string.Format("update xg_gg set url='{0}',flag=-1 where id={1}", xg.Url.ToUpper(), xg.ID);

                using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sql, null);
                            trans.Commit();
                            Console.WriteLine("新股公告内容更新成功!");
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 更新单个股票公告信息
        /// </summary>
        /// <param name="code"></param>
        private static void UpXgGG(string code) 
        {
            string _url = string.Format("http://data.eastmoney.com/Notice/Notice_Stock_List.aspx?code={0}", code);
            string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
            MatchCollection mcSubCon = Regex.Matches(_Content, "<li>[^>]+><a[^>]+>[^>]+></span>[^>]+<span class=\"time\">[^>]+</span>[^>]+<span class=\"type\">[^>]+>[^>]+>", RegexOptions.IgnoreCase);

            StringBuilder sqlsb = new StringBuilder();
            List<XgGgEntity> list = NewsList.XgGgListQuery(string.Format(" and gpdm='{0}'", code));
            Console.WriteLine("开始采集新股" + code + "公告信息");
            foreach (Match mc in mcSubCon)
            {
                string mcstr = mc.Value;
                Match urlmc = Regex.Match(mcstr, "Notice_Detail.aspx[^\"]+", RegexOptions.IgnoreCase);
                Match titlemc = Regex.Match(mcstr, "<a[^>]+>[^<]+", RegexOptions.IgnoreCase);
                Match timemc = Regex.Match(mcstr, "<span class=\"time\">[^<]+", RegexOptions.IgnoreCase);
                Match typemc = Regex.Match(mcstr, "<span class=\"type\">[^<]+", RegexOptions.IgnoreCase);

                string url = urlmc.Value.ToUpper();
                string title = Regex.Replace(titlemc.Value, "<a[^>]+>", "", RegexOptions.IgnoreCase);
                string time = Regex.Replace(timemc.Value, "<[^>]+>", "", RegexOptions.IgnoreCase);
                string type = Regex.Replace(typemc.Value, "<[^>]+>", "", RegexOptions.IgnoreCase);

                var re = list.Where(a => a.Url == url);
                if (re.Count() <= 0)
                {
                    Console.WriteLine("正在采集" + url);
                    sqlsb.AppendFormat("insert into XG_GG (url,title,ggrq,gpdm,ggtype) values ('{0}','{1}','{2}','{3}','{4}')\r\n", url, title, time, code, type);
                }
                else
                {
                    break;
                }
            }

            #region 执行SQL
            if (!string.IsNullOrEmpty(sqlsb.ToString()))
            {
                using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sqlsb.ToString(), null);
                            trans.Commit();
                            Console.WriteLine("新股" + code + "公告信息更新成功!");
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            Console.WriteLine("新股" + code + "公告信息更新异常:" + ex.Message);
                            LogFile.WriteLog("新股" + code + "公告信息更新异常:" + ex.Message);
                        }
                    }
                }
            }
            #endregion
        }

        /// <summary>
        /// 采集 东财增发申购数据 http://data.eastmoney.com/xg/zf/default.html UrlList
        /// </summary>
        /// <param name="page">传入采集第几页,page=0采集所有页</param>
        private static void IrtZfListUrl(int page)
        {
            StringBuilder sql = new StringBuilder();
            List<ZfDetailEntity> ListAll = new List<ZfDetailEntity>();
            ListAll = (List<ZfDetailEntity>)NewsList.ZfListAll("");

            string _url = "", _Content = "";
            int _page = 1;

            for (int i = 1; i <= _page; i++)
            {
                try
                {
                    _url = "http://data.eastmoney.com/xg/zf/default.html";
                    _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mc = Regex.Match(_Content, "(?<=class=\"rpager\">当前第)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mc.Value))
                    {
                        #region
                        MatchCollection mc2 = Regex.Matches(mc.Value, "href=\"/xg/zf/detail/\\d{6}.html\" class=\"red\">详细</a", RegexOptions.IgnoreCase);
                        for (int j = 0; j < mc2.Count; j++)
                        {
                            try
                            {
                                Match mc3 = Regex.Match(mc2[j].Value, "(?<=href=\")[\\s\\S]*?(?=\")", RegexOptions.IgnoreCase);
                                if (mc3.Length > 0)
                                {
                                    ZfDetailEntity et = new ZfDetailEntity();
                                    et.Url = "http://data.eastmoney.com" + OperMethod.StrReplaceHtml(mc3.Value);
                                    List<ZfDetailEntity> MidList = (List<ZfDetailEntity>)ListAll.Where(o => o.Url.Equals(et.Url)).ToList();
                                    if (MidList == null || MidList.Count < 1)
                                    {
                                        sql.Append("insert ZF_Detail (url,flag,createtime) values ('" + et.Url + "',-1,'" + DateTime.Now + "')      ;\n");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("取列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                                LogFile.WriteLog("取列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                            }
                        }
                        #endregion
                    }

                    if (!string.IsNullOrEmpty(sql.ToString()))
                    {
                        SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        sql = new StringBuilder();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集东财增发申购数据第" + i + "页信息时出错");
                    LogFile.WriteLog("采集东财增发申购数据第" + i + "页信息时出错");
                }
            }
            Console.WriteLine("采集东财增发申购数据列表完成");
        }

        /// <summary>
        /// 更新东财增发申购数据UrlList信息
        /// </summary>
        private static void UpZfListByUrl()
        {
            StringBuilder sbZfDetail = new StringBuilder();
            List<ZfDetailEntity> ListAll = (List<ZfDetailEntity>)NewsList.ZfListAll(" and flag=-1 ");
            List<ZfDetailEntity> MidList = (List<ZfDetailEntity>)ListAll.Where(o => o.Flag.Equals(-1)).ToList();
            for (int i = 0; i < MidList.Count; i++)
            {
                try
                {
                    Console.WriteLine("采集东财增发申购数据第i=" + i.ToString() + "条信息");
                    string _url = MidList[i].Url;
                    int _ID = MidList[i].ID;
                    //_url = "http://data.eastmoney.com/xg/zf/detail/600481.html";
                    string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mcSubCon = Regex.Match(_Content, "(?<=id=\"content\">)[\\s\\S]*?(?=id=\"footer\">)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mcSubCon.Value))
                    {
                        //Zf_Detail东财增发详细资料
                        #region
                        ZfDetailEntity et = new ZfDetailEntity();
                        MatchCollection mcTd = Regex.Matches(mcSubCon.Value, "<td[\\S\\s]*?>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                        DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
                        for (int j = 0; j < mcTd.Count; j++)
                        {
                            #region
                            try
                            {
                                Regex regex = new Regex("<td[^>][\\S\\s]*?>|</td>|<div[^>][\\S\\s]*?>|</div>");
                                if (mcTd[j].Value.Contains("增发代码"))
                                {
                                    j++;
                                    et.Zfdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("增发简称"))
                                {
                                    j++;
                                    et.Zfjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("股票代码"))
                                {
                                    j++;
                                    et.Gpdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("股票简称"))
                                {
                                    j++;
                                    et.Gpjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("发行方式"))
                                {
                                    j++;
                                    et.Fxfs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("发行价格"))
                                {
                                    j++;
                                    et.Fxjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("网上发行日期"))
                                {
                                    j++;
                                    et.Fxrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("网上发行股数"))
                                {
                                    j++;
                                    et.Fxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("网下发行日期"))
                                {
                                    j++;
                                    et.Psrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("网下配售股数"))
                                {
                                    j++;
                                    et.Psgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("增发上市日期"))
                                {
                                    j++;
                                    et.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("总发行股数"))
                                {
                                    j++;
                                    et.Zfxgs = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("发行结果公布日") || mcTd[j].Value.Contains("中签号公布日"))
                                {
                                    j++;
                                    et.Zqr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("网上发行配售率") || mcTd[j].Value.Contains("网上发行中签率"))
                                {
                                    j++;
                                    et.Zql = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("冻结资金"))
                                {
                                    j++;
                                    et.Djzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("每中一股资金"))
                                {
                                    j++;
                                    et.Ygzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("中签号"))
                                {
                                    j++;
                                    et.Zqh = OperMethod.FormatHtml(mcTd[j].Value);
                                    et.Zqh = regex.Replace(et.Zqh, "");
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("募集资金用途"))
                                {
                                    j++;
                                    et.Zjyt = OperMethod.FormatHtml(mcTd[j].Value);
                                    et.Zjyt = regex.Replace(et.Zjyt, "");
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("主营业务"))
                                {
                                    j++;
                                    et.Zyyw = OperMethod.FormatHtml(mcTd[j].Value);
                                    et.Zyyw = regex.Replace(et.Zyyw, "");
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("发行前总股本"))
                                {
                                    j++;
                                    et.Fxqzgb = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("发行后总股本"))
                                {
                                    j++;
                                    et.FxhZgb = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("承销方式"))
                                {
                                    j++;
                                    et.Cxfs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("承销期起止时间"))
                                {
                                    j++;
                                    et.Cxqzsj = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("副主承销商"))
                                {
                                    j++;
                                    et.Fzcxs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("主承销商"))
                                {
                                    j++;
                                    et.Zcxs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("首日开盘价"))
                                {
                                    j++;
                                    et.Kpj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("首日收盘价"))
                                {
                                    j++;
                                    et.Spj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("首日涨幅"))
                                {
                                    j++;
                                    et.Zf = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }

                            }
                            catch (Exception ex)
                            { }
                            #endregion
                        }
                        #endregion

                        //拼Sql
                        #region
                        sbZfDetail.Append(" UPDATE [ZF_Detail]");
                        sbZfDetail.Append(" SET [flag] = 0");
                        sbZfDetail.Append(" ,[zfdm] = '" + et.Zfdm + "'");
                        sbZfDetail.Append(" ,[zfjc] = '" + et.Zfjc + "'");
                        sbZfDetail.Append(" ,[gpdm] = '" + et.Gpdm + "'");
                        sbZfDetail.Append(" ,[gpjc] = '" + et.Gpjc + "'");
                        sbZfDetail.Append(" ,[fxfs] = '" + et.Fxfs + "'");
                        sbZfDetail.Append(" ,[fxjg] = " + et.Fxjg + "");
                        sbZfDetail.Append(" ,[fxrq] = '" + et.Fxrq + "'");
                        sbZfDetail.Append(" ,[fxgs] = " + et.Fxgs + "");
                        sbZfDetail.Append(" ,[psrq] = '" + et.Psrq + "'");
                        sbZfDetail.Append(" ,[psgs] = " + et.Psgs + "");
                        sbZfDetail.Append(" ,[ssrq] = '" + et.Ssrq + "'");
                        sbZfDetail.Append(" ,[zfxgs] = " + et.Zfxgs + "");
                        sbZfDetail.Append(" ,[zqr] = '" + et.Zqr + "'");
                        sbZfDetail.Append(" ,[zql] = " + et.Zql + "");
                        sbZfDetail.Append(" ,[djzj] = " + et.Djzj + "");
                        sbZfDetail.Append(" ,[ygzj] = " + et.Ygzj + "");
                        sbZfDetail.Append(" ,[zqh] = '" + et.Zqh + "'");
                        sbZfDetail.Append(" ,[zjyt] = '" + et.Zjyt + "'");
                        sbZfDetail.Append(" ,[zyyw] = '" + et.Zyyw + "'");
                        sbZfDetail.Append(" ,[fxqzgb] = " + et.Fxqzgb + "");
                        sbZfDetail.Append(" ,[fxhzgb] = " + et.FxhZgb + "");
                        sbZfDetail.Append(" ,[cxfs] = '" + et.Cxfs + "'");
                        sbZfDetail.Append(" ,[cxqzsj] = '" + et.Cxqzsj + "'");
                        sbZfDetail.Append(" ,[zcxs] = '" + et.Zcxs + "'");
                        sbZfDetail.Append(" ,[fzcxs] = '" + et.Fzcxs + "'");
                        sbZfDetail.Append(" ,[kpj] = " + et.Kpj + "");
                        sbZfDetail.Append(" ,[spj] = " + et.Spj + "");
                        sbZfDetail.Append(" ,[zf] = " + et.Zf + "");
                        sbZfDetail.Append(" ,[stype] = '" + et.Stype + "'");
                        sbZfDetail.Append(" ,[createtime] = '" + DateTime.Now + "'");
                        sbZfDetail.Append(" WHERE id=" + _ID);
                        #endregion
                    }
                }
                catch (Exception ex)
                { }
            }

            if (!string.IsNullOrEmpty(sbZfDetail.ToString()))
            {
                int n = SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sbZfDetail.ToString(), null);
                sbZfDetail = new StringBuilder();
                Console.WriteLine("本次更新" + n.ToString() + "条东财增发申购数据信息。");
            }
        }


        /// <summary>
        /// 采集 可转债股票数据 http://data.eastmoney.com/xg/kzz/default.html  UrlList
        /// </summary>
        /// <param name="page">传入采集第几页,page=0采集所有页</param>
        private static void IrtKzzListUrl(int page)
        {
            StringBuilder sql = new StringBuilder();
            List<KzzDetailEntity> ListAll = new List<KzzDetailEntity>();
            ListAll = (List<KzzDetailEntity>)NewsList.KzzListAll("");

            string _url = "", _Content = "";
            int _page = 1;

            for (int i = 1; i <= _page; i++)
            {
                try
                {
                    _url = "http://data.eastmoney.com/xg/kzz/default.html ";
                    _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mc = Regex.Match(_Content, "(?<=class=\"rpager\">当前第)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mc.Value))
                    {
                        #region
                        MatchCollection mc2 = Regex.Matches(mc.Value, "href=\"/xg/kzz/detail/\\d{6}.html\" class=\"red\">详细</a", RegexOptions.IgnoreCase);
                        for (int j = 0; j < mc2.Count; j++)
                        {
                            try
                            {
                                Match mc3 = Regex.Match(mc2[j].Value, "(?<=href=\")[\\s\\S]*?(?=\")", RegexOptions.IgnoreCase);
                                if (mc3.Length > 0)
                                {
                                    KzzDetailEntity et = new KzzDetailEntity();
                                    et.Url = "http://data.eastmoney.com" + OperMethod.StrReplaceHtml(mc3.Value);
                                    List<KzzDetailEntity> MidList = (List<KzzDetailEntity>)ListAll.Where(o => o.Url.Equals(et.Url)).ToList();
                                    if (MidList == null || MidList.Count < 1)
                                    {
                                        sql.Append("insert Kzz_Detail (url,flag,createtime) values ('" + et.Url + "',-1,'" + DateTime.Now + "')      ;\n");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("采集可转债股票数据列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                                LogFile.WriteLog("采集可转债股票数据列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                            }
                        }
                        #endregion
                    }

                    if (!string.IsNullOrEmpty(sql.ToString()))
                    {
                        int n = SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        sql = new StringBuilder();
                        Console.WriteLine("采集到可转债股票数据" + n.ToString() + "条");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集可转债股票数据第" + i + "页信息时出错");
                    LogFile.WriteLog("采集可转债股票数据第" + i + "页信息时出错");
                }
            }
            Console.WriteLine("采集可转债股票数据列表完成");
        }


        /// <summary>
        /// 更新 可转债股票数据 UrlList信息
        /// </summary>
        private static void UpKzzListByUrl()
        {
            StringBuilder sbKzzDetail = new StringBuilder();
            StringBuilder sbWarrant = new StringBuilder();
            List<KzzDetailEntity> ListAll = (List<KzzDetailEntity>)NewsList.KzzListAll(" and flag=-1 ");
            List<KzzDetailEntity> MidList = (List<KzzDetailEntity>)ListAll.Where(o => o.Flag.Equals(-1)).ToList();
            for (int i = 0; i < MidList.Count; i++)
            {
                try
                {
                    Console.WriteLine("采集可转债股票数据第i=" + i.ToString() + "条信息");
                    string _url = MidList[i].Url;
                    int _ID = MidList[i].ID;
                    //_url = "http://data.eastmoney.com/xg/kzz/detail/126018.html";
                    string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mcSubCon = Regex.Match(_Content, "(?<=id=\"content\">)[\\s\\S]*?(?=id=\"footer\">)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mcSubCon.Value))
                    {
                        //Kzz_Detail东财增发详细资料
                        #region
                        KzzDetailEntity et = new KzzDetailEntity();
                        KZZWarrantEntity etw = new KZZWarrantEntity();
                        MatchCollection mcTd = Regex.Matches(mcSubCon.Value, "<td[\\S\\s]*?>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                        DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
                        for (int j = 0; j < mcTd.Count; j++)
                        {
                            #region
                            try
                            {
                                Regex regex = new Regex("<td[^>][\\S\\s]*?>|</td>|<div[^>][\\S\\s]*?>|</div>");
                                if (mcTd[j].Value.Contains("债券代码"))
                                {
                                    j++;
                                    et.Zqdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("债券简称"))
                                {
                                    j++;
                                    et.Zqjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("股票代码"))
                                {
                                    j++;
                                    et.Gpdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("股票简称"))
                                {
                                    j++;
                                    et.Gpjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("认购代码"))
                                {
                                    j++;
                                    et.Rgdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("认购简称"))
                                {
                                    j++;
                                    et.Rgjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("申购代码"))
                                {
                                    j++;
                                    et.Sgdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("申购简称"))
                                {
                                    j++;
                                    et.Sgjc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("信用级别"))
                                {
                                    j++;
                                    et.Xyjb = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("评级机构"))
                                {
                                    j++;
                                    et.Pjjg = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("转股期") || mcTd[j].Value.Contains("预设利率区间"))
                                {
                                    j++;
                                    et.Ztq = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("初始转股价格") || mcTd[j].Value.Contains("最终发行利率"))
                                {
                                    j++;
                                    et.Ztjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("发行份额"))
                                {
                                    j++;
                                    et.Fxfe = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("发行价格"))
                                {
                                    j++;
                                    et.Fxjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("债券期限"))
                                {
                                    j++;
                                    et.Zqqx = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("网上网下发行比例"))
                                {
                                    j++;
                                    et.Fxbl = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("申购日期"))
                                {
                                    j++;
                                    et.Sgrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("配售比例"))
                                {
                                    j++;
                                    et.Psbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("上市日期"))
                                {
                                    string _temp = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    if (_temp.Trim().Equals("上市日期"))
                                    {
                                        j++;
                                        et.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                        _temp = "";
                                        continue;
                                    }
                                }
                                if (mcTd[j].Value.Contains("中签号公布日"))
                                {
                                    j++;
                                    et.Gbr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("网上发行中签率"))
                                {
                                    j++;
                                    et.Zql = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("每中一签资金"))
                                {
                                    j++;
                                    et.Yqzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("冻结资金"))
                                {
                                    j++;
                                    et.Djzj = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("中签号"))
                                {
                                    j++;
                                    et.Zqh = OperMethod.FormatHtml(mcTd[j].Value);
                                    et.Zqh = regex.Replace(et.Zqh, "");
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("募集资金用途"))
                                {
                                    j++;
                                    et.Zjyt = OperMethod.FormatHtml(mcTd[j].Value);
                                    et.Zjyt = regex.Replace(et.Zjyt, "");
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("担保事项"))
                                {
                                    j++;
                                    et.Dbsx = OperMethod.FormatHtml(mcTd[j].Value);
                                    et.Dbsx = regex.Replace(et.Dbsx, "");
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("票面利率"))
                                {
                                    j++;
                                    et.Pmll = OperMethod.FormatHtml(mcTd[j].Value);
                                    et.Pmll = regex.Replace(et.Pmll, "");
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("重设条款"))
                                {
                                    j++;
                                    et.Cstk = OperMethod.FormatHtml(mcTd[j].Value);
                                    et.Cstk = regex.Replace(et.Cstk, "");
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("回售条款"))
                                {
                                    j++;
                                    et.Hstk = OperMethod.FormatHtml(mcTd[j].Value);
                                    et.Hstk = regex.Replace(et.Hstk, "");
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("赎回条款"))
                                {
                                    j++;
                                    et.Shtk = OperMethod.FormatHtml(mcTd[j].Value);
                                    et.Shtk = regex.Replace(et.Shtk, "");
                                    continue;
                                }

                                //附属权证资料
                                if (mcTd[j].Value.Contains("权证代码"))
                                {
                                    j++;
                                    etw.Qzdm = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("权证名称"))
                                {
                                    j++;
                                    etw.Qzmc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("权证类型"))
                                {
                                    j++;
                                    etw.Qzlx = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("权证发行总量"))
                                {
                                    j++;
                                    etw.Qzfxzl = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("初始行权价格"))
                                {
                                    j++;
                                    etw.Xqjg = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("初始行权比例"))
                                {
                                    j++;
                                    etw.Xqbl = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("权证上市日期"))
                                {
                                    j++;
                                    etw.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("债券附送权证比例"))
                                {
                                    j++;
                                    etw.Qzbl = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("权证存续起始日"))
                                {
                                    j++;
                                    etw.Qsr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("权证存续终止日"))
                                {
                                    j++;
                                    etw.Zzr = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[j].Value), _ErrDt);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("行权期"))
                                {
                                    j++;
                                    etw.Xqq = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }
                                if (mcTd[j].Value.Contains("发行人"))
                                {
                                    j++;
                                    etw.Fxr = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                    continue;
                                }

                            }
                            catch (Exception ex)
                            { }
                            #endregion
                        }
                        #endregion

                        //拼Sql
                        #region
                        sbKzzDetail.Append(" UPDATE [KZZ_Detail]");
                        sbKzzDetail.Append(" SET [flag] = 0");
                        sbKzzDetail.Append(" ,[zqdm] = '" + et.Zqdm + "'");
                        sbKzzDetail.Append(" ,[zqjc] = '" + et.Zqjc + "'");
                        sbKzzDetail.Append(" ,[gpdm] = '" + et.Gpdm + "'");
                        sbKzzDetail.Append(" ,[gpjc] = '" + et.Gpjc + "'");
                        sbKzzDetail.Append(" ,[rgdm] = '" + et.Rgdm + "'");
                        sbKzzDetail.Append(" ,[rgjc] = '" + et.Rgjc + "'");
                        sbKzzDetail.Append(" ,[sgdm] = '" + et.Sgdm + "'");
                        sbKzzDetail.Append(" ,[sgjc] = '" + et.Sgjc + "'");
                        sbKzzDetail.Append(" ,[xyjb] = '" + et.Xyjb + "'");
                        sbKzzDetail.Append(" ,[pjjg] = '" + et.Pjjg + "'");
                        sbKzzDetail.Append(" ,[ztq] = '" + et.Ztq + "'");
                        sbKzzDetail.Append(" ,[ztjg] = " + et.Ztjg + "");
                        sbKzzDetail.Append(" ,[fxfe] = " + et.Fxfe + "");
                        sbKzzDetail.Append(" ,[fxjg] = " + et.Fxjg + "");
                        sbKzzDetail.Append(" ,[zqqx] = '" + et.Zqqx + "'");
                        sbKzzDetail.Append(" ,[fxbl] = '" + et.Fxbl + "'");
                        sbKzzDetail.Append(" ,[sgrq] = '" + et.Sgrq + "'");
                        sbKzzDetail.Append(" ,[psbl] = " + et.Psbl + "");
                        sbKzzDetail.Append(" ,[ssrq] = '" + et.Ssrq + "'");
                        sbKzzDetail.Append(" ,[gbr] = '" + et.Gbr + "'");
                        sbKzzDetail.Append(" ,[zql] = " + et.Zql + "");
                        sbKzzDetail.Append(" ,[yqzj] = " + et.Yqzj + "");
                        sbKzzDetail.Append(" ,[djzj] = " + et.Djzj + "");
                        sbKzzDetail.Append(" ,[zqh] = '" + et.Zqh + "'");
                        sbKzzDetail.Append(" ,[zjyt] = '" + et.Zjyt + "'");
                        sbKzzDetail.Append(" ,[dbsx] = '" + et.Dbsx + "'");
                        sbKzzDetail.Append(" ,[pmll] = '" + et.Pmll + "'");
                        sbKzzDetail.Append(" ,[cstk] = '" + et.Cstk + "'");
                        sbKzzDetail.Append(" ,[hstk] = '" + et.Hstk + "'");
                        sbKzzDetail.Append(" ,[shtk] = '" + et.Shtk + "'");
                        sbKzzDetail.Append(" ,[createtime] = '" + DateTime.Now + "'");
                        sbKzzDetail.Append(" WHERE id=" + _ID);

                        //Warrant
                        if (et.Zqjc.Contains("转债").Equals(false))
                        {
                            sbWarrant.Append("INSERT INTO [KZZ_Warrant] ([id] ,[qzdm] ,[qzmc] ,[qzlx] ,[qzfxzl] ,[xqjg] ,[xqbl] ");
                            sbWarrant.Append(" ,[ssrq] ,[qzbl] ,[qsr] ,[zzr] ,[xqq] ,[fxr]) ");
                            sbWarrant.Append(" VALUES (" + _ID + " ,'" + etw.Qzdm + "' ,'" + etw.Qzmc + "' ,'" + etw.Qzlx + "' ," + etw.Qzfxzl + " ," + etw.Xqjg + " ");
                            sbWarrant.Append(" ,'" + etw.Xqbl + "' ,'" + etw.Ssrq + "' ,'" + etw.Qzbl + "' ,'" + etw.Qsr + "' ,'" + etw.Zzr + "' ,'" + etw.Xqq + "' ,'" + etw.Fxr + "')");
                        }
                        #endregion
                    }

                    using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                    {
                        conn.Open();
                        using (SqlTransaction trans = conn.BeginTransaction())
                        {
                            if (!string.IsNullOrEmpty(sbKzzDetail.ToString()))
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbKzzDetail.ToString(), null);
                            if (!string.IsNullOrEmpty(sbWarrant.ToString()))
                                SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbWarrant.ToString(), null);
                            trans.Commit();
                            sbKzzDetail = new StringBuilder();
                            sbWarrant = new StringBuilder();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集更新第" + i.ToString() + "条信息时出错：" + ex.Message);
                    LogFile.WriteLog("采集更新第" + i.ToString() + "条信息时出错：" + ex.Message);
                }
            }
        }



        /// <summary>
        /// 采集新股上会 http://data.eastmoney.com/xg/gh/default.html UrlList
        /// </summary>
        /// <param name="page">传入采集第几页,page=0采集所有页</param>
        private static void IrtShListUrl(int page)
        {
            StringBuilder sql = new StringBuilder();
            List<ShDetailEntity> ListAll = (List<ShDetailEntity>)NewsList.ShListAll("");
            DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
            string _url = "", _Content = "";
            int _page = 1;
            if (page == 0)
            {
                _url = "http://data.eastmoney.com/xg/gh/default.html";
                _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                Match mc = Regex.Match(_Content, "(?<=<tr class=\"list_pager\">)[\\s\\S]*?(?=</tr>)");
                if (mc.Length > 0)
                {
                    Match mc2 = Regex.Match(mc.Value, "(?<=共)[\\s\\S]*?(?=页)", RegexOptions.IgnoreCase);
                    if (mc2.Length > 0)
                        _page = OperMethod.ToInt(OperMethod.StrReplaceHtml(mc2.Value));
                }
            }

            for (int i = 1; i <= _page; i++)
            {
                try
                {
                    _url = "http://data.eastmoney.com/xg/gh/sbrq/" + i.ToString() + ".html";
                    _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mc = Regex.Match(_Content, "(?<=class=\"rpager\">当前第)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mc.Value))
                    {
                        #region

                        MatchCollection mc2 = Regex.Matches(mc.Value, "<tr[^>][\\S\\s]*?>[\\S\\s]*?</tr>", RegexOptions.IgnoreCase);
                        for (int j = 0; j < mc2.Count; j++)
                        {
                            try
                            {
                                MatchCollection mcTd = Regex.Matches(mc2[j].Value, "<td>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                                if (mcTd.Count == 12 && (mc2[j].Value.Contains("class=\"list_odd\"") || mc2[j].Value.Contains("class=\"list_eve\">")))
                                {
                                    ShDetailEntity et = new ShDetailEntity();
                                    Match mcUrl = Regex.Match(mcTd[9].Value, "(?<=href=\")[\\s\\S]*?(?=\")", RegexOptions.IgnoreCase);
                                    et.Url = "http://data.eastmoney.com" + OperMethod.StrReplaceHtml(mcUrl.Value.Trim());
                                    et.Sbrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[2].Value), _ErrDt);
                                    et.Dqzt = OperMethod.StrReplaceHtml(mcTd[3].Value);
                                    et.Shrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[4].Value), _ErrDt);
                                    et.Sgrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[5].Value), _ErrDt);
                                    et.Ssrq = OperMethod.ToDate(OperMethod.StrReplaceHtml(mcTd[6].Value), _ErrDt);
                                    et.Ssdd = OperMethod.StrReplaceHtml(mcTd[8].Value);

                                    List<ShDetailEntity> MidList = (List<ShDetailEntity>)ListAll.Where(o => o.Url.Equals(et.Url)).ToList();
                                    if (MidList == null || MidList.Count < 1)
                                    {
                                        sql.Append("insert SH_Detail (url,flag,createtime,sbrq,dqzt,Shrq,Sgrq,Ssrq,Ssdd) values ('" + et.Url + "',-1,'" + DateTime.Now + "','" + et.Sbrq + "','" + et.Dqzt + "','" + et.Shrq + "','" + et.Sgrq + "','" + et.Ssrq + "','" + et.Ssdd + "')      ;\n");
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("采集新股上会列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                                LogFile.WriteLog("采集新股上会列表Url第" + j.ToString() + "条时出错:" + ex.Message);
                            }
                        }

                        #endregion
                    }

                    if (!string.IsNullOrEmpty(sql.ToString()))
                    {
                        int n = SQLHelper.ExecuteNonQuery(SQLHelper.StrConn, CommandType.Text, sql.ToString(), null);
                        sql = new StringBuilder();
                        Console.WriteLine("本页page=" + i.ToString() + "采集信息" + n.ToString() + "条");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集新股上会第" + i + "页信息时出错");
                    LogFile.WriteLog("采集新股上会第" + i + "页信息时出错");
                }
            }
        }


        /// <summary>
        /// 更新新股过会　UrlList　信息
        /// </summary>
        private static void UpShListByUrl()
        {
            Regex regex = new Regex("<td[^>][\\S\\s]*?>|</td>|<div[^>][\\S\\s]*?>|</div>");
            List<ShDetailEntity> ListAll = (List<ShDetailEntity>)NewsList.ShListAll(" and flag=-1");
            List<ShDetailEntity> MidList = (List<ShDetailEntity>)ListAll.Where(o => o.Flag.Equals(-1)).ToList();
            for (int i = 0; i < MidList.Count; i++)
            {
                try
                {
                    Console.WriteLine("采集第i=" + i.ToString() + "条信息");
                    string _url = MidList[i].Url;
                    int _ID = MidList[i].ID;
                    //_url = "http://data.eastmoney.com/xg/gh/detail/corp_209.html#list";
                    string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                    Match mcSubCon = Regex.Match(_Content, "(?<=id=\"content\"  class=\"mainbox\">)[\\s\\S]*?(?=id=\"footer\">)", RegexOptions.IgnoreCase);
                    if (!string.IsNullOrEmpty(mcSubCon.Value))
                    {
                        //SH_Detail详细资料
                        #region
                        StringBuilder sbDetail = new StringBuilder();
                        Match mcDetail = Regex.Match(mcSubCon.Value, "(?<=——新股上会详细概况)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                        if (!string.IsNullOrEmpty(mcDetail.Value))
                        {
                            ShDetailEntity et = new ShDetailEntity();
                            MatchCollection mcTd = Regex.Matches(mcDetail.Value, "<td[\\S\\s]*?>[\\S\\s]*?</td>", RegexOptions.IgnoreCase);
                            DateTime _ErrDt = DateTime.Parse("1900-1-1 0:00:00");
                            for (int j = 0; j < mcTd.Count; j++)
                            {
                                #region
                                try
                                {
                                    if (mcTd[j].Value.Contains("公司名称"))
                                    {
                                        j++;
                                        et.Gsmc = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行前总股本"))
                                    {
                                        j++;
                                        et.Fxqzgb = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("拟发行后总股本"))
                                    {
                                        j++;
                                        et.Fxhzgb = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("拟发行数量"))
                                    {
                                        j++;
                                        et.Fxsl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("占发行后总股本"))
                                    {
                                        j++;
                                        et.Zbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value.Replace("%", "")));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("重要财务指标"))
                                    {
                                        j++;
                                        et.Cwjb = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("每股收益"))
                                    {
                                        j++;
                                        et.Mgsy = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("发行前每股净资产"))
                                    {
                                        j++;
                                        et.Jzc = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("每股现金流量"))
                                    {
                                        j++;
                                        et.Xjll = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("净资产收益率"))
                                    {
                                        j++;
                                        et.Syl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[j].Value));
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("主营业务"))
                                    {
                                        j++;
                                        et.Zyyw = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("利润分配"))
                                    {
                                        j++;
                                        et.Lrfp = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("主承销商"))
                                    {
                                        j++;
                                        et.Zcxs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                    if (mcTd[j].Value.Contains("承销方式"))
                                    {
                                        j++;
                                        et.Cxfs = OperMethod.StrReplaceHtml(mcTd[j].Value);
                                        continue;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Detail取字段" + mcTd[j].Value + "附近异常:" + ex.Message);
                                    LogFile.WriteLog("Detail取字段" + mcTd[j].Value + "附近异常:" + ex.Message);
                                }
                                #endregion
                            }

                            //拼sbDetail Sql
                            #region
                            sbDetail.Append("UPDATE [SH_Detail]");
                            sbDetail.Append(" SET [flag] = 0");
                            sbDetail.Append(" ,[gsmc] = '" + et.Gsmc + "'");
                            sbDetail.Append(" ,[fxqzgb] = " + et.Fxqzgb + "");
                            sbDetail.Append(" ,[fxhzgb] = " + et.Fxhzgb + "");
                            sbDetail.Append(" ,[fxsl] = " + et.Fxsl + "");
                            sbDetail.Append(" ,[zbl] = " + et.Zbl + "");
                            sbDetail.Append(" ,[cwjb] = '" + et.Cwjb + "'");
                            sbDetail.Append(" ,[mgsy] = " + et.Mgsy + "");
                            sbDetail.Append(" ,[jzc] = " + et.Jzc + "");
                            sbDetail.Append(" ,[xjll] = " + et.Xjll + "");
                            sbDetail.Append(" ,[syl] = " + et.Syl + "");
                            sbDetail.Append(" ,[zyyw] = '" + et.Zyyw + "'");
                            sbDetail.Append(" ,[lrfp] = '" + et.Lrfp + "'");
                            sbDetail.Append(" ,[zcxs] = '" + et.Zcxs + "'");
                            sbDetail.Append(" ,[cxfs] = '" + et.Cxfs + "'");
                            sbDetail.Append(" ,[createtime] = '" + DateTime.Now + "'");
                            sbDetail.Append(" WHERE ID=" + _ID);
                            Console.WriteLine("Detail拼Sql完成");
                            #endregion
                        }
                        #endregion

                        //Sh_Invset投资项目
                        #region
                        StringBuilder sbInvset = new StringBuilder();
                        Match mcInvset = Regex.Match(mcSubCon.Value, "(?<=募集资金用途将用于的项目</div>)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                        if (!string.IsNullOrEmpty(mcInvset.Value))
                        {
                            MatchCollection mcTr = Regex.Matches(mcInvset.Value, "(?<=<tr)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                            for (int k = 0; k < mcTr.Count; k++)
                            {
                                try
                                {
                                    if (mcTr[k].Value.Contains("class=\"list_eve\">") || mcTr[k].Value.Contains("class=\"list_odd\">"))
                                    {
                                        MatchCollection mcTd = Regex.Matches(mcTr[k].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                                        if (mcTd.Count == 3)
                                        {
                                            ShInvsetEntity et = new ShInvsetEntity();
                                            et.Xmmc = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                            et.tzje = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[2].Value));
                                            sbInvset.Append("Insert into SH_Invset (id,xmmc,tzje) values (" + _ID + ",'" + et.Xmmc + "'," + et.tzje + ")    ;\n");
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("新股过会募集资金用途将用于的项目异常:" + ex.Message);
                                    LogFile.WriteLog("新股过会募集资金用途将用于的项目异常:" + ex.Message);
                                }
                            }
                        }
                        Console.WriteLine("取Sh_Invset投资项目信息完成");
                        #endregion

                        //XG_Indicators财务指标
                        #region
                        StringBuilder sbIndicator = new StringBuilder();
                        Match mcIndicator = Regex.Match(mcSubCon.Value, "(?<=最近三年财务指标</div>)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                        if (!string.IsNullOrEmpty(mcIndicator.Value))
                        {
                            List<EntityIndicatorCol> CList = new List<EntityIndicatorCol>();
                            MatchCollection mcTr = Regex.Matches(mcIndicator.Value, "(?<=<tr)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                            for (int m = 0; m < mcTr.Count; m++)
                            {
                                try
                                {
                                    EntityIndicatorCol cet = new EntityIndicatorCol();

                                    if (mcTr[m].Value.Contains("class=\"subhead\">"))
                                    {
                                        MatchCollection mcTd = Regex.Matches(mcTr[m].Value, "<th[\\S\\s]*?>[\\S\\s]*?</th>", RegexOptions.IgnoreCase);
                                        if (mcTd.Count > 0)
                                        {
                                            cet.zd = OperMethod.StrReplaceHtml(mcTd[0].Value);
                                            cet.c1 = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                            cet.c2 = OperMethod.StrReplaceHtml(mcTd[2].Value);
                                            cet.c3 = OperMethod.StrReplaceHtml(mcTd[3].Value);
                                            CList.Add(cet);
                                        }
                                        continue;
                                    }

                                    if (mcTr[m].Value.Contains("class=\"list_eve\">") || mcTr[m].Value.Contains("class=\"list_odd\">"))
                                    {
                                        MatchCollection mcTd = Regex.Matches(mcTr[m].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                                        if (mcTd.Count > 0)
                                        {
                                            cet.zd = OperMethod.StrReplaceHtml(mcTd[0].Value);
                                            cet.c1 = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                            cet.c2 = OperMethod.StrReplaceHtml(mcTd[2].Value);
                                            cet.c3 = OperMethod.StrReplaceHtml(mcTd[3].Value);
                                            CList.Add(cet);
                                        }
                                        continue;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("解析装载到List出错:" + ex.Message);
                                    LogFile.WriteLog("解析装载到List出错:" + ex.Message);
                                }
                            }

                            if (CList.Count == 11)
                            {
                                sbIndicator.Append(" INSERT INTO [SH_Indicators] ");
                                sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                                sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c1 + "'," + OperMethod.ToDeceimal(CList[1].c1) + "," + OperMethod.ToDeceimal(CList[2].c1) + "," + OperMethod.ToDeceimal(CList[3].c1) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c1) + "," + OperMethod.ToDeceimal(CList[5].c1) + "," + OperMethod.ToDeceimal(CList[6].c1) + "," + OperMethod.ToDeceimal(CList[7].c1) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c1) + "," + OperMethod.ToDeceimal(CList[9].c1) + "," + OperMethod.ToDeceimal(CList[10].c1) + ")    ;\n");

                                sbIndicator.Append(" INSERT INTO [SH_Indicators] ");
                                sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                                sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c2 + "'," + OperMethod.ToDeceimal(CList[1].c2) + "," + OperMethod.ToDeceimal(CList[2].c2) + "," + OperMethod.ToDeceimal(CList[3].c2) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c2) + "," + OperMethod.ToDeceimal(CList[5].c2) + "," + OperMethod.ToDeceimal(CList[6].c2) + "," + OperMethod.ToDeceimal(CList[7].c2) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c2) + "," + OperMethod.ToDeceimal(CList[9].c2) + "," + OperMethod.ToDeceimal(CList[10].c2) + ")    ;\n");

                                sbIndicator.Append(" INSERT INTO [SH_Indicators] ");
                                sbIndicator.Append(" ([id],[nian],[zzc],[jzc],[gdsy],[jlr],[zbgj],[wfplr],[jbmgsy],[xsmgsy],[xjl],[jzcsyl]) ");
                                sbIndicator.Append(" VALUES (" + _ID + ",'" + CList[0].c3 + "'," + OperMethod.ToDeceimal(CList[1].c3) + "," + OperMethod.ToDeceimal(CList[2].c3) + "," + OperMethod.ToDeceimal(CList[3].c3) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[4].c3) + "," + OperMethod.ToDeceimal(CList[5].c3) + "," + OperMethod.ToDeceimal(CList[6].c3) + "," + OperMethod.ToDeceimal(CList[7].c3) + " ");
                                sbIndicator.Append(" ," + OperMethod.ToDeceimal(CList[8].c3) + "," + OperMethod.ToDeceimal(CList[9].c3) + "," + OperMethod.ToDeceimal(CList[10].c3) + ")    ;\n");
                            }
                        }
                        Console.WriteLine("取Sh_Indicators最近三年财务指标完成");
                        #endregion

                        //XG_Partner主要股东
                        #region
                        StringBuilder sbPartner = new StringBuilder();
                        Match mcPartner = Regex.Match(mcSubCon.Value, "(?<=主要股东</div>)[\\s\\S]*?(?=</table>)", RegexOptions.IgnoreCase);
                        if (!string.IsNullOrEmpty(mcPartner.Value))
                        {
                            MatchCollection mcTr = Regex.Matches(mcPartner.Value, "(?<=class=\"list_eve\">)[\\s\\S]*?(?=</tr>)", RegexOptions.IgnoreCase);
                            for (int x = 0; x < mcTr.Count; x++)
                            {
                                try
                                {
                                    MatchCollection mcTd = Regex.Matches(mcTr[x].Value, "(?<=<td>)[\\s\\S]*?(?=</td>)", RegexOptions.IgnoreCase);
                                    if (mcTd.Count == 4)
                                    {
                                        ShPartnerEntity et = new ShPartnerEntity();
                                        et.Gdmc = OperMethod.StrReplaceHtml(mcTd[1].Value);
                                        et.Cgsl = OperMethod.ToInt(OperMethod.StrReplaceHtml(mcTd[2].Value));
                                        et.Gbbl = OperMethod.ToDeceimal(OperMethod.StrReplaceHtml(mcTd[3].Value));
                                        sbPartner.Append("INSERT INTO [SH_Partner] ([id],[gdmc],[cgsl],[gbbl]) VALUES (" + _ID + ",'" + et.Gdmc + "'," + et.Cgsl + "," + et.Gbbl + ")    ;\n");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("新股上会主要股东异常:" + ex.Message);
                                    LogFile.WriteLog("新股上会主要股东异常:" + ex.Message);
                                }
                            }
                        }
                        Console.WriteLine("采集更新新股上会XG_Partner主要股东完成");
                        #endregion

                        //执行Sql
                        #region
                        using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                        {
                            conn.Open();
                            using (SqlTransaction trans = conn.BeginTransaction())
                            {
                                try
                                {
                                    if (!string.IsNullOrEmpty(sbDetail.ToString()))
                                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbDetail.ToString(), null);
                                    if (!string.IsNullOrEmpty(sbInvset.ToString()))
                                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbInvset.ToString(), null);
                                    int n = 0;
                                    if (!string.IsNullOrEmpty(sbIndicator.ToString()))
                                        n = SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbIndicator.ToString(), null);
                                    if (!string.IsNullOrEmpty(sbPartner.ToString()))
                                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbPartner.ToString(), null);
                                    trans.Commit();
                                    Console.WriteLine("ID=" + _ID + ",Url=" + _url + "新股上会信息更新成功!");
                                }
                                catch (Exception ex)
                                {
                                    trans.Rollback();
                                    Console.WriteLine("执行新股上会Sql异常,ID:" + _ID + ":" + ex.Message);
                                    LogFile.WriteLog("执行新股上会Sql异常,ID:" + _ID + ":" + ex.Message);
                                }
                                finally
                                {
                                    sbDetail = new StringBuilder();
                                    sbInvset = new StringBuilder();
                                    sbIndicator = new StringBuilder();
                                    sbPartner = new StringBuilder();
                                }
                            }
                        }
                        #endregion
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("采集新股上会第i=" + i.ToString() + "条信息异常" + ex.Message);
                    LogFile.WriteLog("采集新股上会第i=" + i.ToString() + "条信息异常" + ex.Message);
                }
            }
            Console.WriteLine("新股上会信息更新成功");
        }
        #endregion

        #region 抓取交易提示
        /// <summary>
        /// 抓取交易提示
        /// </summary>
        private static void UpJyts()
        {
            #region 抓取上证所数据
            string _url = "http://www.sse.com.cn/sseportal/webapp/datapresent/querytradetipsnew";
            string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
            Match mcTitle = Regex.Match(_Content, "<td class=\"Title_l\" valign=\"top\" width=\"100%\">(?<g1>[\\d]{4}\\-[\\d]{2}\\-[\\d]{2})[^<]*</td>");
            string title = mcTitle.Groups["g1"].Value;
            StringBuilder sbsql = new StringBuilder();
            if (!chkTitle(title, 1))
            {
                MatchCollection mcs = Regex.Matches(_Content, "<tr bgcolor=\"#F4F4F4\" height=\"20\">([^<]+(<td[^>]+>[^<]+</td>)){5}([^<]+</tr>)");
                foreach (Match mc in mcs)
                {
                    string mcContent = mc.Value;
                    MatchCollection tmcs = Regex.Matches(mcContent, "<td class=\"table3\" bgcolor=\"((#dbedf8)|(white))\" nowrap>[^<]+</td>");
                    string gpdm = Regex.Replace(tmcs[0].Value, "<[^>]+>", "", RegexOptions.IgnoreCase);
                    string gpjc = Regex.Replace(tmcs[1].Value, "<[^>]+>", "", RegexOptions.IgnoreCase);
                    string tpsj = Regex.Replace(tmcs[2].Value, "<[^>]+>", "", RegexOptions.IgnoreCase);
                    string tpqx = Regex.Replace(tmcs[3].Value, "<[^>]+>", "", RegexOptions.IgnoreCase);
                    string tpyy = Regex.Replace(tmcs[4].Value, "<[^>]+>", "", RegexOptions.IgnoreCase);
                    sbsql.AppendFormat("insert into kp_jyts (gpdm,gpjc,tpsj,tpqx,tpyy,source,title) values ('{0}','{1}','{2}','{3}','{4}',1,'{5}')\r\n", gpdm, gpjc, tpsj, tpqx, tpyy, title);
                }
            }
            else 
            {
                Console.WriteLine("上交所交易提示无更新!");
            }
            #endregion

            #region 抓取深交所数据
            _url = "http://www.szse.cn/main/disclosure/news/tfpts/";
            _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
            mcTitle = Regex.Match(_Content, "<span class='cls-subtitle'>(?<g1>[\\d]{4}\\-[\\d]{2}\\-[\\d]{2})</span>");
            title = mcTitle.Groups["g1"].Value;
            if (!chkTitle(title, 2))
            {
                MatchCollection mcs = Regex.Matches(_Content, "<tr  class='cls-data-tr'[^>]+>(<td[^>]*>[^<]*</td>){6}</tr>");
                foreach (Match mc in mcs)
                {
                    string xml = mc.Value;
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(xml);
                    XmlNodeList nodes = doc.GetElementsByTagName("td");
                    string gpdm = nodes[0].InnerText.Trim();
                    string gpjc = nodes[1].InnerText.Trim();
                    string tpsj = nodes[2].InnerText.Trim();
                    //string gbrq = nodes[0].InnerText;
                    string fpsj = nodes[3].InnerText.Trim();
                    string tpqx = nodes[4].InnerText.Trim();
                    string tpyy = nodes[5].InnerText.Trim();

                    sbsql.AppendFormat("insert into kp_jyts (gpdm,gpjc,tpsj,tpqx,fpsj,tpyy,source,title) values ('{0}','{1}','{2}','{3}','{4}','{5}',2,'{6}')\r\n", gpdm, gpjc, tpsj, tpqx, fpsj, tpyy, title);
                }
            }
            else
            {
                Console.WriteLine("深交所交易提示无更新!");
            }
            #endregion

            string sql = sbsql.ToString();

            #region 执行SQL
            if (!string.IsNullOrEmpty(sbsql.ToString()))
            {
                using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sbsql.ToString(), null);
                            trans.Commit();
                            Console.WriteLine("交易提示更新完成!");
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            Console.WriteLine("交易提示更新异常:" + ex.Message);
                            LogFile.WriteLog("交易提示更新异常:" + ex.Message);
                        }
                    }
                }
            }
            #endregion
        }
        /// <summary>
        /// 交易提示是否已更新
        /// </summary>
        /// <param name="title"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private static bool chkTitle(string title,int type) 
        {
            string sql = string.Format("select id from kp_jyts where title='{0}' and source={1}", title, type);
            SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.StrConn, CommandType.Text, sql, null);
            int id = 0;
            if (reader.Read()) 
            {
                id = int.Parse(reader["id"].ToString());
            }
            if (id > 0) 
            {
                return true;
            }
            return false;
        }
        #endregion

        #region 交易公开信息
        /// <summary>
        /// 获取上交所交易公开信息
        /// </summary>
        private static void UpShJygkxx()
        {
            #region 上交所
            string _url = "http://www.sse.com.cn/sseportal/webapp/datapresent/SSENewTradeInfoPublishAct";
            string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
            Match mc = Regex.Match(_Content, "<td class=\"content_gkjy\" valign=\"top\" width=\"100%\">(?<g1>[\\s\\S]*)</td>");
            string content = mc.Groups["g1"].Value.Split(new string[] { "</td>" }, StringSplitOptions.None)[0];
            content = content.Replace("\r\n\r\n\r\n", "");
            Match mcdate = Regex.Match(content, "(?<year>[\\d]{4})年(?<mouth>[\\d]{2})月(?<day>[\\d]{2})日");
            string date = string.Format("{0}-{1}-{2}", mcdate.Groups["year"].Value, mcdate.Groups["mouth"].Value, mcdate.Groups["day"].Value);
            string sql = "";
            if (!chkJygkxx(date, 1))
            {
                sql = string.Format("insert into kp_gkxx (xxrq,content,source) values ('{0}','{1}',1)\r\n", date, content);
            }
            else 
            {
                Console.WriteLine("上交所交易公开信息无更新!");
            }
            #endregion

            DateTime dt = DateTime.Now.AddDays(-1);
            _url = string.Format("http://www.szse.cn/szseWeb/common/szse/files/text/jy/jy{0}.txt", dt.ToString("yyMMdd"));
            _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
            if (!string.IsNullOrEmpty(_Content) && !chkJygkxx(dt.ToString("yyyy-MM-dd"), 2))
            {
                sql += string.Format("insert into kp_gkxx (xxrq,content,source) values ('{0}','{1}',2)\r\n", dt.ToString("yyyy-MM-dd"), _Content);
            }
            else 
            {
                Console.WriteLine("深交所交易公开信息无更新!");
            }
            

            #region 执行SQL
            if (!string.IsNullOrEmpty(sql))
            {
                using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sql, null);
                            trans.Commit();
                            Console.WriteLine("交易公开信息更新完成!");
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            Console.WriteLine("交易公开信息更新异常:" + ex.Message);
                            LogFile.WriteLog("交易公开信息更新异常:" + ex.Message);
                        }
                    }
                }
            }
            #endregion
        }

        private static bool chkJygkxx(string date, int type) 
        {
            string sql = string.Format("select id from kp_gkxx where xxrq='{0}' and source={1}", date, type);
            SqlDataReader reader = SQLHelper.ExecuteReader(SQLHelper.StrConn, CommandType.Text, sql, null);
            int id = 0;
            if (reader.Read())
            {
                id = int.Parse(reader["id"].ToString());
            }
            if (id > 0)
            {
                return true;
            }
            return false;
        }
        #endregion

        #region 采集期货信息
        public static void upFuture() 
        {
            //string _url = "http://hq2gjqh.eastmoney.com/EM_Futures2010NumericApplication/index.aspx?type=z&ids=CONH0,HONH0,GLNJ0,SLNH0,CHCH0,SBCH0,WHCH0,CRCH0,SMCH0,SOCH0,CTNH0,LCPS0,LALS0,LZNS0,LTNS0,LNKS0,LLDS0";
            string _url = "http://hq2gjqh.eastmoney.com/EM_Futures2010NumericApplication/index.aspx?type=z&ids=CONK0,HONJ0,GLNJ0,SLNN0,CHCK0,SBCK0,WHCK0,CRCK0,SMCK0,SOCK0,CTNK0,LCPS0,LALS0,LZNS0,LTNS0,LNKS0,LLDS0";
            string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
            _Content = _Content.Replace("var js=", "");
            //var re = Newtonsoft.Json.JsonConvert.DeserializeObject(_Content);
            MatchCollection mcs = Regex.Matches(_Content, "\"(?<g1>[^\"]*)\"");
            StringBuilder sqlb = new StringBuilder();
            foreach (Match mc in mcs)
            {
                string value = mc.Value;
                string[] args = value.Split(new char[] { ',' });                
                switch (args[0].Replace("\"",""))
                {
                    case "CONK0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='轻质原油'\r\n", args[5], args[18]);
                        break;
                    case "HONK0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='燃料油'\r\n", args[5], args[18]);
                        break;
                    case "GLNK0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='黄金'\r\n", args[5], args[18]);
                        break;
                    case "SLNK0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='白银'\r\n", args[5], args[18]);
                        break;
                    //case "CHCH0":
                    //    sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='轻质原油'\r\n", args[5], args[18]);
                    //    break;
                    case "SBCK0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='大豆'\r\n", args[5], args[18]);
                        break;
                    case "WHCK0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='小麦'\r\n", args[5], args[18]);
                        break;
                    case "CRCK0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='玉米'\r\n", args[5], args[18]);
                        break;
                    case "SMCK0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='豆粕'\r\n", args[5], args[18]);
                        break;
                    case "SOCK0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='豆油'\r\n", args[5], args[18]);
                        break;
                    case "CTNK0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='棉花'\r\n", args[5], args[18]);
                        break;
                    case "LCPS0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='3月铜'\r\n", args[5], args[18]);
                        break;
                    case "LALS0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='3月铝'\r\n", args[5], args[18]);
                        break;
                    case "LZNS0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='3月锌'\r\n", args[5], args[18]);
                        break;
                    case "LTNS0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='3月锡'\r\n", args[5], args[18]);
                        break;
                    case "LNKS0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='3月镍'\r\n", args[5], args[18]);
                        break;
                    case "LLDS0":
                        sqlb.AppendFormat("update ZS_ContentData set newprice='{0}',ZDF='{1}' where name='3月铅'\r\n", args[5], args[18]);
                        break;
                    default:
                        break;
                }
            }
            string sql = sqlb.ToString();
            #region 执行SQL
            if (!string.IsNullOrEmpty(sql))
            {
                using (SqlConnection conn = new SqlConnection(SQLHelper.StrConn))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            SQLHelper.ExecuteNonQuery(trans, CommandType.Text, sql, null);
                            trans.Commit();
                            Console.WriteLine("期货信息更新成功!");
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                            Console.WriteLine("期货信息更新异常:" + ex.Message);
                            LogFile.WriteLog("期货信息更新异常:" + ex.Message);
                        }
                    }
                }
            }
            #endregion
        }
        #endregion




        /// <summary>
        /// 新股日程报告
        /// </summary>
        private static void UpXgReportByUrl()
        {
            StringBuilder sql = new StringBuilder();
            Regex regex = new Regex("<td[^>][\\S\\s]*?>|</td>|<div[^>][\\S\\s]*?>|</div>");
            List<XgDetailEntity> ListAll = (List<XgDetailEntity>)NewsList.XgListAll("and flag>0");
            List<XgDetailEntity> MidList = (List<XgDetailEntity>)ListAll.ToList();
            for (int i = 0; i < MidList.Count; i++)
            {
                try
                {
                    Console.WriteLine("采集第i=" + i.ToString() + "条信息");
                    string _url = MidList[i].Url;
                    int _ID = MidList[i].ID;
                    string _Content = OperMethod.GetPageByUrl(_url, "Gb2312");
                }
                catch { }
            }
        }



    }

    public class EntityIndicatorCol
    {
        public string zd { get; set; }
        public string c1 { get; set; }
        public string c2 { get; set; }
        public string c3 { get; set; }
    }
}
